﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using System.Data;
public partial class admin_现金助学_待走访贫困生 : BLL.BasePage_Admin
{
    Appeal bll_Appeal = new Appeal();
    Role bll_Role = new Role();
    User_Volunteer bll_User_Volunteer = new User_Volunteer();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            UIInit();
        }
    }

    private void UIInit()
    {
        Bind_GridView();
        Set_PagingCount();
    }
    private void Set_PagingCount()
    {
        AspNetPager1.RecordCount = bll_Appeal.GetRecordCount(GetWhere());
    }

    private void Bind_GridView()
    {
        DataTable dt = bll_Appeal.GetListByPage(GetWhere(), "InsTime desc", AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex + AspNetPager1.PageSize).Tables[0];
        dt.Columns.Add("District");
        dt.Columns.Add("Check_Name");
        Helper_District helper_District = new Helper_District();
        foreach (DataRow dr in dt.Rows)
        {
            dr["District"] = helper_District.Get_FullPath_DistrictId(Convert.ToInt32(dr["DistrictId"]), Helper_District.ShowType.无符号连接);
            //dr["Check_Name"] = bll_User_Volunteer.GetModel(Convert.ToInt32(dr["Id"])).Nickname;
        }
        GridView1.DataSource = dt;
        GridView1.DataBind();
        lblPagingInfo.Text = PublicControlBind.GetPagingInfo(dt.Rows.Count, (AspNetPager1.StartRecordIndex - 1) / AspNetPager1.PageSize + 1, AspNetPager1.PageSize);
    }
    /// <summary>
    /// 拼装where
    /// </summary>
    /// <returns></returns>
    private string GetWhere()
    {
        string where = "1=1";
        where += " and IsPass1 = 1 and IsReject1 = 0";
        where += GetWhere_Date(txtFromDate.Text, txtToDate.Text, "InsTime");
        where += GetWhere_Str_Like(txtName.Text.Trim(), "name");
        where += GetWhere_List(ddlType.SelectedValue, "sex");
        return where;
    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
        string sqlStr = "update Appeal set IsDelete = 1 where id = " + id;
        DAL.Common.ExecuteSql(sqlStr);
        Bind_GridView();
        Set_PagingCount();
    }
    /// <summary>
    /// 分页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Bind_GridView();
    }
    /// <summary>
    /// 搜索
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (!Check_Date(txtFromDate.Text, txtToDate.Text))
        {
            return;
        }
        Bind_GridView();
        Set_PagingCount();
    }
}